package com.w3cjava.modules.index;

import com.w3cjava.common.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @Autowired
    public RedisUtil redisUtil;

    @GetMapping("/setRedis")
    public String hello() {
        redisUtil.set("test", "test");
        return "success";
    }

    @GetMapping("/getRedis")
    public String redis() {
        redisUtil.set("test", "test");
        return (String) redisUtil.get("test");
    }

    /**
     * 测试redis注解
     */
    @Autowired
    private UserService userService;
    @GetMapping("/saveUser")
    public String saveUser() {
        User user = new User("1", "w3cjava", 18);
        userService.saveUser(user);
        return "success";
    }

    @GetMapping("/getUser")
    public String getUser() {
        User user = userService.getUserById("1");
        return user.getName();
    }

    @GetMapping("/deleteUser")
    public String deleteUser() {
        userService.deleteUserById("1");
        return "success";
    }


}